package com.scientific.research.gobang.config;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RedissonConfig {

    @Value("${spring.redis.sentinel.nodes}")
    String url;
    @Value("${spring.redis.password}")
    String password;

    @Bean
    public RedissonClient getRedisson() {
        Config config = new Config();
        config.useSentinelServers()
                .setMasterName("mymaster")
                .addSentinelAddress("redis://" + url)//URL前面必须加上redis://采用SSL连接，否则报错
                .setDatabase(1)
                .setPassword(password);
        return Redisson.create(config);
    }

}
